package com.yanggeng.demo.beginnerguidedemo.activity.customview;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.yanggeng.demo.beginnerguidedemo.R;
import com.yanggeng.demo.beginnerguidedemo.activity.BaseActivity;
import com.yanggeng.demo.beginnerguidedemo.bean.Topology;
import com.yanggeng.demo.beginnerguidedemo.widget.TopologyView;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class TopologyActivity extends BaseActivity {

    private TopologyView topologyView;
    private String[] types = {"DMU", "DEU", "SEU", "AMU", "DRU", "ARU"};

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_topology);
        setTitle(true, "TopologyView", "刷新");
        topologyView = (TopologyView) findViewById(R.id.topology);
        updateData();
    }

    @Override
    protected void navigationOnclick(int paramId) {
        super.navigationOnclick(paramId);
        if (paramId == RIGHT_TEXT) {
            updateData();
        }
    }

    private void updateData() {
        Random random = new Random();
        Topology topology = new Topology();
        topology.setSize(5);
        topology.setTier(0);
        topology.setType(types[random.nextInt(6)]);
        List<Topology.PortBean> portBeans = new ArrayList<>();
        for (int i = 0; i < random.nextInt(5); i++) {
            Topology.PortBean portBean = new Topology.PortBean();
            Topology temp = new Topology();
            temp.setSize(i + 3);
            temp.setTier(1);
            temp.setType(types[random.nextInt(6)]);
            List<Topology.PortBean> portBeans1 = new ArrayList<>();
            for (int j = 0; j < random.nextInt(temp.getSize()); j++) {
                Topology.PortBean portBean1 = new Topology.PortBean();
                Topology temp1 = new Topology();
                temp1.setSize(j + 2);
                temp1.setTier(2);
                temp1.setType(types[random.nextInt(6)]);
                List<Topology.PortBean> portBeans2 = new ArrayList<>();
                for (int k = 0; k < random.nextInt(temp1.getSize()); k++) {
                    Topology.PortBean portBean2 = new Topology.PortBean();
                    Topology temp2 = new Topology();
                    temp2.setSize(k + 1);
                    temp2.setTier(3);
                    temp2.setType(types[random.nextInt(6)]);
                    portBean2.setDevice(temp2);
                    portBeans2.add(portBean2);
                }
                temp1.setPorts(portBeans2);
                portBean1.setDevice(temp1);
                portBeans1.add(portBean1);
            }
            temp.setPorts(portBeans1);
            portBean.setDevice(temp);
            portBeans.add(portBean);
        }
        topology.setPorts(portBeans);

        topologyView.setData(topology);
    }
}
